package com.shiguiwu.springmybatis.spring.imports.registrar;

import lombok.Data;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @description: ImportBeanDefinitionRegistrar的子类
 * @author: stone
 * @date: Created by 2021/9/29 16:42
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.imports.registrar
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Import1.class).getBeanDefinition();
        BeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition(Import2.class)
                .addPropertyReference("import1","import1").getBeanDefinition();
        registry.registerBeanDefinition("import1", beanDefinition);
        registry.registerBeanDefinition("import2", beanDefinition2);
    }


    public static class Import1 {

    }


    @Data
    public static class Import2 {
        private Import1 import1;
    }
}
